package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.GetStatisticsDataRequestDTO;
import com.smile.model.response.response.GetStatisticsDataResponseDTO;
import com.smile.model.request.GetStatisticsDataRequest;
import com.smile.model.response.*;
import com.smile.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @PostMapping("/getStatisticsData")
    public R<GetStatisticsDataResponse> getStatisticsData(@RequestBody GetStatisticsDataRequest getStatisticsDataRequest) {

        GetStatisticsDataRequestDTO getStatisticsDataRequestDTO = BeanUtil.copyProperties(getStatisticsDataRequest, GetStatisticsDataRequestDTO.class);

        GetStatisticsDataResponseDTO getStatisticsDataResponseDTO = statisticsService.getStatisticsData(getStatisticsDataRequestDTO);

        List<GetStatisticsAirportByFlyCountsListResponse> getStatisticsDataResponsesByFlyCount =
                BeanUtil.copyToList(getStatisticsDataResponseDTO.
                        getGetStatisticsAirportListResponseDTOByFlyCount(), GetStatisticsAirportByFlyCountsListResponse.class);


        List<GetStatisticsAirportByFlyTimesListResponse> getStatisticsDataResponsesByFlyTime =
                BeanUtil.copyToList(getStatisticsDataResponseDTO.
                        getGetStatisticsAirportByFlyTimesListResponseDTOS(), GetStatisticsAirportByFlyTimesListResponse.class);

        List<GetStatisticsAirportByFlyDistanceListResponse> getStatisticsDataResponsesByFlyDistance =
                BeanUtil.copyToList(getStatisticsDataResponseDTO.
                                getGetStatisticsAirportListResponseDTOByFlyDistance(),
                        GetStatisticsAirportByFlyDistanceListResponse.class);


//        List<GetFlyDetailStatisticsResponse> getFlyDetailStatisticsResponses =
//                BeanUtil.copyToList(getStatisticsDataResponseDTO.getFlyDetailStatistics(), GetFlyDetailStatisticsResponse.class);


        GetStatisticsDataResponse getStatisticsDataResponse = BeanUtil.copyProperties(getStatisticsDataResponseDTO, GetStatisticsDataResponse.class);
        getStatisticsDataResponse.setGetStatisticsDataResponseByFlyCount(getStatisticsDataResponsesByFlyCount);
        getStatisticsDataResponse.setGetStatisticsDataResponseByFlyTimes(getStatisticsDataResponsesByFlyTime);
        getStatisticsDataResponse.setGetStatisticsDataResponseByFlyDistance(getStatisticsDataResponsesByFlyDistance);


        return R.ok(getStatisticsDataResponse);
    }

}
